package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.account.CheckSameLabelCompanyBean;
import com.info.zhiduoduo.admin.model.formbean.account.GetAnEnterpriseContractBean;
import com.info.zhiduoduo.admin.model.formbean.company.*;
import com.info.zhiduoduo.admin.model.formbean.crm.UpdateIncomingFormBean;
import com.info.zhiduoduo.admin.model.formbean.system.LoginFormBean;
import com.info.zhiduoduo.admin.service.CompanyService;
import com.info.zhiduoduo.common.annotation.DependOnEntity;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.common.validator.IntIn;
import com.info.zhiduoduo.repository.dto.company.*;
import com.info.zhiduoduo.repository.entity.company.*;

import com.info.zhiduoduo.repository.entity.system.AccountLinkLabel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.Positive;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.IOException;

@Validated
@Api(tags = "管理端 企业信息")
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    CompanyService companyService;

    @ZddLog(name = "login")
    @PostMapping("/login")
    public SmartResult companyLogin(@RequestBody BaseSimpleFormBean<LoginFormBean> formBean) {
        return companyService.login(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE, name = "修改企业设置", entities = {
            @LogEntity(entity = Company.class, parameters = @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")),
            @LogEntity(entity = CompanyAccount.class, dependOnEntities = @DependOnEntity(entity = Company.class, fields = "compid", parameters = "compid"))
    })
    @ApiOperation("企业设置")
    @PostMapping("/setting")
    public SmartResult companySetting(@RequestBody BaseSimpleFormBean<CompanySetting> formBean) {
        return companyService.companySetting(formBean.getReqdata().getCompid(),formBean.getReqdata());
    }

    @ApiOperation("查询企业设置")
    @PostMapping("/getSetting")
    public SmartResult<CompanySetting> getSetting(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.getSetting(formBean.getReqdata());
    }

    @ApiOperation("查询企业支付设置列表")
    @PostMapping("/getPayList")
    public SmartResult<CompanyPayment> getPayList(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return SmartResult.success(companyService.getCompanyPayList(formBean.getReqdata()));
    }

    /**
     * 获取企业认证列表
     */
    @ZddLog(type = ZddLogType.QUERY,name = "获取企业认证列表")
    @PostMapping("/verifyList")
    public SmartResult verifyList(@RequestBody BaseSimpleFormBean<CompanyListFormBean> formBean) {
        return companyService.getVerifyList(formBean);
    }
    /**
     * 导出未上传已过期的合同
     */
    @ApiOperation("导出未上传已过期的合同")
    @GetMapping("/exportVerifyList")
    public void exportVerifyList(HttpServletResponse response) throws IOException {
        companyService.exportVerifyList(response);
    }

    /**
     * 获取企业实名详情
     */
    @PostMapping("/accountDetail")
    public SmartResult getAccountDetail(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.getAccountDetail(formBean);
    }

    /**
     * 获取企业所有详细资料
     */
    @PostMapping("/allInfo")
    public SmartResult<CompanyDetailDto> getCompanyAllInfo(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.getCompanyAllInfo(formBean);
    }

    /**
     * 实名审核企业,通过或驳回
     */
    @PostMapping("/verify")
    public SmartResult verifyCompany(@RequestBody BaseSimpleFormBean<VerifyCompanyFormBean> formBean) {
        return companyService.verifyCompany(formBean);
    }

    /**
     * 编辑企业实名信息
     */
    @ZddLog(type = ZddLogType.UPDATE,name = "编辑企业实名信息",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @PostMapping("/edit")
    public SmartResult editCompany(@RequestBody BaseSimpleFormBean<EditCompanyFormBean> formBean) {
        return companyService.editCompany(formBean);
    }
    /**
     * 批量修改显示招商银行
     */
    @PostMapping("/modifyDisplayList")
    public SmartResult modifyDisplayList(@RequestBody BaseSimpleFormBean<ModifyDisplayListFormBean> formBean) {
        return companyService.modifyDisplayList(formBean);
    }

    @PostMapping("/queryCompany")
    public SmartResult queryCompanyList(@RequestBody BaseSimpleFormBean<String> formBean) {
        return companyService.queryCompanyList(formBean);
    }

    @ZddLog(name = "创建公司")
    @PostMapping("/createCompany")
    public SmartResult createCompany(@RequestBody BaseSimpleFormBean<CreateCompanyFormBean> formBean) {
        return companyService.createCompany(formBean);
    }

    @ZddLog(type = ZddLogType.DELETE,name = "删除公司",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata")))
    @PostMapping("/delCompany")
    public SmartResult delCompany(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.delCompany(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "changeCompanyState",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @PostMapping("/changeState")
    public SmartResult changeCompanyState(@RequestBody BaseSimpleFormBean<CompanyStateFormBean> formBean) {
        return companyService.changeCompanyState(formBean);
    }

    @ApiOperation("设置友好企业标识")
    @PostMapping("/setCompanyFriendlyState")
    public SmartResult setCompanyFriendlyState(@RequestBody @Validated BaseSimpleFormBean<CompanyFriendlyStateFormBean> formBean) {
        return companyService.setCompanyFriendlyState(formBean);
    }

    @ApiOperation("设置委托接单功能")
    @PostMapping("/setEntrustedReceiptStatus")
    public SmartResult setEntrustedReceiptStatus(@RequestBody @Validated BaseSimpleFormBean<EntrustedReceiptStatusFormBean> formBean){
        return companyService.setEntrustedReceiptStatus(formBean);
    }

    /**
     * 重新审核企业，将已审核的企业变为审核中
     */
    @ZddLog(type = ZddLogType.UPDATE,name = "重新审核企业，将已审核的企业变为审核中",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @PostMapping("/reverify")
    public SmartResult reverifyCompany(@RequestBody BaseSimpleFormBean<VerifyCompanyFormBean> formBean) {
        return companyService.reverifyCompany(formBean);
    }

    /**
     * 创建企业账户在开联通支付中到账号
     */
    @ZddLog(name = "创建企业账户在开联通支付中到账号")
    @PostMapping("/addKltMerchant")
    public SmartResult addCompanyKltMerchant(@RequestBody BaseSimpleFormBean<AddMerchantFormBean> formBean) {
        return companyService.addCompanyKltMerchant(formBean);
    }

    /**
     * 查询企业的开联通开户商户账号状态
     */
    @PostMapping("/queryKltMerchant")
    public SmartResult queryKltMerchant(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.queryKltMerchant(formBean);
    }


    @PostMapping("/editInviteCode")
    public SmartResult editInviteCode(@RequestBody BaseSimpleFormBean<EditInviteCodeFormBean> formBean) {
        return companyService.editInviteCode(formBean);
    }

    /**
     * 设置或取消企业是否开启智众包模式
     *
     * @param formBean
     * @return
     */
    @ZddLog(type = ZddLogType.UPDATE,name = "设置智众包",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation("设置智众包")
    @PostMapping("/setCrowdsource")
    public SmartResult setCrowdsource(@Valid @RequestBody BaseSimpleFormBean<SetCompanyCrowdsourceFormBean> formBean) {
        return companyService.setCompanyCrowdsource(formBean);
    }

    @ApiOperation("获取智众包签约人员")
    @PostMapping("/crowdsourceList")
    public SmartResult getIntelCrowdsourceCompanyList(@RequestBody BaseSimpleFormBean<String> formBean) {
        return companyService.getIntelCrowdsourceList(formBean);
    }

    //企业解约
    @ZddLog(type = ZddLogType.UPDATE,name = "企业解约",entities = @LogEntity(entity = Company.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata")))
    @PostMapping("/companyRescission")
    public SmartResult companyRescission(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.companyRescission(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "编辑显示核心模块",entities = @LogEntity(entity = CompanyAccount.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation("编辑显示核心模块")
    @PostMapping("/editCoreModule")
    public SmartResult editCoreModule(@RequestBody BaseSimpleFormBean<CoreModuleFormBean> formBean) {
        return companyService.editCoreModule(formBean);
    }


    @ZddLog(type = ZddLogType.UPDATE,name = "设置企业策略性开票",entities = @LogEntity(entity = CompanyAccount.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation("设置企业策略性开票")
    @PostMapping("/setStrategyInvoice")
    public SmartResult setStrategyInvoice(@RequestBody BaseSimpleFormBean<CompanyStrategyInvoiceFormBean> formBean) {
        return companyService.editStrategyInvoice(formBean);
    }

    @ApiOperation("众包企业设置众包项目中合同的起始日期")
    @PostMapping("/setCrowdSourceContractDate")
    public SmartResult setCrowdSourceContractDate(@RequestBody BaseSimpleFormBean<SetContractDateFormBean> formBean) {
        return companyService.setCrowdsourceContractDate(formBean);
    }

    @ApiOperation("补充企业在金蝶的客户编码")
    @PostMapping("/supplementKingdeeCustomerCode")
    public SmartResult supplementKingdeeCustomerCode(@RequestParam("file") MultipartFile file) {
        return companyService.supplementKingdeeCustomerCode(file);
    }

    @ApiOperation("设置企业特殊费率标记")
    @GetMapping("/setSpecialRateFlag")
    public SmartResult setSpecialRateFlag(@RequestParam @Positive int compid, @RequestParam @IntIn({0, 1}) int specialRateFlag) {
        return companyService.setSpecialRateFlag(compid, specialRateFlag);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "设置创客团功能",entities = @LogEntity(entity = CompanyAccount.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation("设置创客团功能")
    @PostMapping("/setMakerGroupon")
    public SmartResult setMakerGroupon(@RequestBody BaseSimpleFormBean<SetMakerGrouponFormBean> formBean) {
        return companyService.setMakerGroupon(formBean);
    }

    @ApiOperation("获取企业转账给创客团账本申请列表")
    @PostMapping("/listApplyTransferMakerGroupon")
    public SmartResult<CompanyTransferMakerGrouponDto> listApplyTransferMakerGroupon(@RequestBody BaseSimpleFormBean<ListTransferMakerGrouponFormBean> formBean) {
        return companyService.listApplyTransferMakerGroupon(formBean);
    }

    @ZddLog(name = "确认企业转账给创客团账本")
    @ApiOperation(value = "确认企业转账给创客团账本", notes = "reqdata: 申请id")
    @PostMapping("/confirmTransferMakerGroupon")
    public SmartResult confirmTransferMakerGroupon(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.confirmTransferMakerGroupon(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "上传委托文件",entities = @LogEntity(entity = CompanyEntrustFile.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation(value = "上传委托文件")
    @PostMapping("/saveCompanyEntrustFile")
    public SmartResult saveCompanyEntrustFile(@RequestBody BaseSimpleFormBean<SaveCompanyEntrustFileFormBean> formBean) {
        return companyService.saveCompanyEntrustFile(formBean);
    }

    @ApiOperation(value = "获取企业的委托文件代办通知")
    @PostMapping("/listCompanyEntrustFileNotification")
    public SmartResult<CompanyEntrustFileNotification> listCompanyEntrustFileNotification(@RequestBody BaseSimpleFormBean<ListCompanyEntrustFileNotificationFormBean> formBean) {
        return companyService.listCompanyEntrustFileNotification(formBean);
    }

    @ApiOperation(value = "获取企业的委托文件列表")
    @PostMapping("/listCompanyEntrustFile")
    public SmartResult<CompanyEntrustFile> listCompanyEntrustFile(@RequestBody BaseSimpleFormBean<ListCompanyEntrustFileFormBean> formBean) {
        return companyService.listCompanyEntrustFile(formBean);
    }

    @ApiOperation(value = "审核企业的委托文件")
    @PostMapping("/auditCompanyEntrustFile")
    public SmartResult<CompanyEntrustFile> auditCompanyEntrustFile(@RequestBody @Valid BaseSimpleFormBean<AuditCompanyEntrustFileFormBean> formBean) {
        return companyService.auditCompanyEntrustFile(formBean);
    }

    @ZddLog(type = ZddLogType.DELETE,name = "删除企业的委托文件",entities = @LogEntity(entity = CompanyEntrustFile.class,parameters =
    @LogParameter(fields = "id",parameters = "formBean.reqdata.id")))
    @ApiOperation(value = "删除企业的委托文件")
    @PostMapping("/delCompanyEntrustFile")
    public SmartResult<CompanyEntrustFile> delCompanyEntrustFile(@RequestBody BaseSimpleFormBean<DelCompanyEntrustFileFormBean> formBean) {
        return companyService.delCompanyEntrustFile(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "修改商务经理",entities = @LogEntity(entity = CompanyAccount.class,parameters =
    @LogParameter(fields = "compid",parameters = "formBean.reqdata.compid")))
    @ApiOperation(value = "修改商务经理")
    @PostMapping("/updateBusinessManager")
    public SmartResult updateBusinessManager(@RequestBody BaseSimpleFormBean<UpdateBusinessManagerFormBean> formBean) {
        return companyService.updateBusinessManager(formBean);
    }

    @ApiOperation(value = "进件表详情")
    @PostMapping("/infoIncoming")
    public SmartResult infoIncoming(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.infoIncoming(formBean);
    }

    @ApiOperation(value = "修改进件表")
    @PostMapping("/updateIncoming")
    public SmartResult updateIncoming(@RequestBody BaseSimpleFormBean<UpdateIncomingFormBean> formBean) {
        return companyService.updateIncoming(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "企业（批量）设置跟单人员")
    @ApiOperation(value = "企业（批量）设置跟单人员")
    @PostMapping("/batchUpdateMerchandiser")
    public SmartResult batchUpdateMerchandiser(@RequestBody BaseSimpleFormBean<UpdateMerchandiserFormBean> formBean) {
        return companyService.batchUpdateMerchandiser(formBean);
    }

    /**
     * 获取所有企业列表，不区分状态
     */
    @PostMapping("/selectCompanyList")
    public SmartResult selectCompanyList(@RequestBody BaseSimpleFormBean<CompanyQueryFormBean> formBean) {
        return companyService.selectCompanyList(formBean);
    }

    @ApiOperation("添加企业评分")
    @PostMapping("/addEnterpriseScore")
    public SmartResult addEnterpriseScore(@RequestBody BaseSimpleFormBean<EnterpriseScoreFormBean> formBean) {
        return companyService.addEnterpriseScore(formBean);
    }
    @ApiOperation("评估报告")
    @PostMapping("/assessmentReport")
    public SmartResult assessmentReport(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.assessmentReport(formBean);
    }

    @ApiOperation("查询评估企业")
    @PostMapping("/EnterpriseScoreList")
    public SmartResult EnterpriseScoreList(@RequestBody BaseSimpleFormBean<EnterpriseScoreListFormBean> formBean) {
        return companyService.EnterpriseScoreList(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE, name = "运营端转充企业余额到企业创客团账户", entities = @LogEntity(entity = CompanyAccount.class, parameters =
    @LogParameter(fields = "compid", parameters = "formBean.reqdata.compid")))
    @ApiOperation("运营端转充企业余额到企业创客团账户")
    @PostMapping("/transferToGrouponBalance")
    public SmartResult transferToGrouponBalance(@RequestBody BaseSimpleFormBean<CompanyGrouponBalanceFormBean> formBean) {
        return companyService.transferToGrouponBalance(formBean);
    }
    @ApiOperation("设置是否代理操作账户标识")
    @PostMapping("/setAgentOperationAccount")
    public SmartResult setAgentOperationAccount(@RequestBody @Validated BaseSimpleFormBean<AgentOperationAccountFormBean> formBean) {
        return companyService.setAgentOperationAccount(formBean);
    }

    @ApiOperation("查询企业年交易额")
    @PostMapping("/queryCompanyYearlyTransAmount")
    public SmartResult queryCompanyYearlyTransAmount(@RequestBody @Validated BaseSimpleFormBean<QueryCompanyAmountFormBean> formBean) {
        return companyService.queryCompanyYearlyTransAmount(formBean);
    }

    @ApiOperation("查询企业招商银行记账子单元列表")
    @PostMapping("/listZhaoShangSubLedger")
    public SmartResult<CompanyZhaoShangSubLedgerDto> listZhaoShangSubLedger(@RequestBody BaseSimpleFormBean<ListZhaoShangSubLedgerFormBean> formBean) {
        return companyService.listZhaoShangSubLedger(formBean);
    }

    @ApiOperation("查询企业招商银行记账子单元充值记录列表")
    @PostMapping("/listZhaoShangSubLedgerRecharge")
    public SmartResult<CompanyZhaoshangSubLedgerRechargeDto> listZhaoShangSubLedgerRecharge(@RequestBody BaseSimpleFormBean<ListZhaoShangSubLedgerRechargeFormBean> formBean) {
        return companyService.listZhaoShangSubLedgerRecharge(formBean);
    }

    @ApiOperation("查询企业招商银行记账子单元充值关联的汇入记录列表")
    @PostMapping("/listZhaoshangSubLedgerRechargeIncomingRecords")
    public SmartResult<CompanyZhaoshangSubLedgerIncomingRecordDto> listZhaoshangSubLedgerRechargeIncomingRecords(
            @RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.listZhaoshangSubLedgerRechargeIncomingRecords(formBean);
    }

    @ApiOperation("编辑企业昵称")
    @PostMapping("/editCompanyNickname")
    public SmartResult editCompanyNickname(@Valid @RequestBody BaseSimpleFormBean<EditCompanyNicknameFormBean> formBean) {
        return companyService.editCompanyNickname(formBean);
    }
    @ApiOperation("添加智合规评分")
    @PostMapping("/addComplianceIntelligence")
    public SmartResult addComplianceIntelligence(@RequestBody BaseSimpleFormBean<AddComplianceIntelligenceFormBean> formBean) {
        return companyService.addComplianceIntelligence(formBean);
    }
    @ApiOperation("获取智合规详情")
    @PostMapping("/complianceDetails")
    public SmartResult complianceDetails(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.complianceDetails(formBean);
    }
    @ApiOperation("发布已经保存的草稿")
    @PostMapping("/publishSavedDrafts")
    public SmartResult publishSavedDrafts(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.publishSavedDrafts(formBean);
    }
    @ApiOperation("获取智合规列表")
    @PostMapping("/getComplianceList")
    public SmartResult getComplianceList(@RequestBody BaseSimpleFormBean<GetComplianceListFormBean> formBean) {
        return companyService.getComplianceList(formBean);
    }

    @ApiOperation("批量修改商务")
    @PostMapping("/batchChangeBusiness")
    public SmartResult batchChangeBusiness(@RequestBody BaseSimpleFormBean<BatchChangeBusinessFormBean> formBean) {
        return companyService.batchChangeBusiness(formBean);
    }

    @ApiOperation("设置自动冻结")
    @PostMapping("/setAutoFreeze")
    public SmartResult setAutoFreeze(@RequestBody BaseSimpleFormBean<SetAutoFreezeFormBean> formBean) {
        return companyService.setAutoFreeze(formBean);
    }


    @ApiOperation("交付物数量")
    @PostMapping("/quantityOfDeliverables")
    public SmartResult<QuantityOfDeliverablesDto> quantityOfDeliverables(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return companyService.quantityOfDeliverables(formBean);
    }

    @ApiOperation("设置有限责任公司")
    @PostMapping("/setUpALimitedLiabilityCompany")
    public SmartResult setUpALimitedLiabilityCompany(@RequestBody BaseSimpleFormBean<SetAutoFreezeFormBean> formBean) {
        return companyService.setUpALimitedLiabilityCompany(formBean);
    }
    @ApiOperation("获取有限责任公司")
    @PostMapping("/liabilityQueryCompany")
    public SmartResult liabilityQueryCompany(@RequestBody BaseSimpleFormBean<String> formBean) {
        return companyService.liabilityQueryCompany(formBean);
    }

    @ApiOperation("校验设置了同一个账号关联企业 标签的企业的费率、合伙人设置是否一致")
    @PostMapping("/checkSameLabelCompanyRate")
    public SmartResult checkSameLabelCompanyRate(@RequestBody BaseSimpleFormBean<CheckSameLabelCompanyBean> formBean) {
        return companyService.checkSameLabelCompanyRate(formBean);
    }

    @ApiOperation("根据账号关联标签查询企业")
    @PostMapping("/queryCompanyByAccountLinkId")
    public SmartResult<Company> queryCompanyByAccountLinkId(@RequestBody BaseSimpleFormBean<Integer> baseSimpleFormBean){
        return companyService.queryCompanyByAccountLinkId(baseSimpleFormBean);
    }

    @ApiOperation("获取企业合同")
    @PostMapping("/getAnEnterpriseContract")
    public SmartResult getAnEnterpriseContract(@RequestBody BaseSimpleFormBean<GetAnEnterpriseContractBean> formBean) {
        return companyService.getAnEnterpriseContract(formBean);
    }

}
